#include"q2.h"
#include<stdio.h>
#include<stdlib.h>

status init(queue *q){
	q->front=NULL;
	q->rear=NULL;
	return ok;
}

status is_empty(queue *q){
	return q->front==NULL;
}

status append(queue *q,datatype e){
	lqnode* node=(lqnode*)malloc(sizeof(lqnode));
	if(!node)exit(overflow);
	node->data=e;
	node->next=NULL;
	if(is_empty(q)){
		q->front=node;
	}else{
		q->rear->next=node;
	}
	q->rear=node;
	return ok;
}

status del(queue *q,datatype *e){
	if(is_empty(q)){
		return error;
	}
	*e=q->front->data;
	q->front=q->front->next;
	return ok;
}

status get_front(queue *q,datatype *e){
	if(is_empty(q)){
		return error;
	}
	*e=q->front->data;
	return ok;
}
void print_rd(datatype d){
	printf("%d ",d);
}
void traverse(queue *q,void(*print_d)(datatype)){
	lqnode *p=q->front;
	while(p){
		print_d(p->data);
		p=p->next;
	}
	printf("\n");
}
int main(){
	queue *q;
	q=(queue*)malloc(sizeof(queue));
	append(q,1);
	append(q,2);
	append(q,3);
	append(q,4);
	append(q,5);
	append(q,6);
	traverse(q,print_rd);
	datatype e;
	del(q,&e);
	printf("%d\n",e);
	traverse(q,print_rd);

}


